package com.sub.kafka.demo;

import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.NewTopic;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName AdminClientDemo
 * @Description: Kafka管理客户端
 * @Author Submerge.
 * @Since 2025/6/1 17:00
 * @Version 1.0
 */
public class AdminClientDemo {

    public static void main(String[] args) {

        Map<String, Object> conf = new HashMap<>();
        conf.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");

        //创建AdminClient对象
        AdminClient adminClient = AdminClient.create(conf);

        //创建主题，参数：主题名称，分区数，副本数
        adminClient.createTopics(Collections.singletonList(new NewTopic("admin-topic", 1, (short) 1)));

        adminClient.close();
    }
}
